package presenter;

import base.BasePresenter;
import base.ResultCallBack;
import bean.CodeBean;
import bean.GuangGaoBean;
import bean.LoginBean;
import bean.Loginby_phonecodeBean;
import model.GuangGaoModel;
import model.LoginModel;
import view.LoginView;
import view.YingDaoView;

/**
 * Created by Windows on 2019/11/5.
 */

public class LoginPresenter extends BasePresenter<LoginView> {
    private LoginModel model;

    public LoginPresenter() {
        this.model=new LoginModel();
        addModel(model);
    }

    //请求登录接口
    public void requestLogin(String name,String pwd) {
        model.requestLogin(new ResultCallBack<LoginBean>() {
            @Override
            public void onSuccess(LoginBean loginBean) {
                if (mView!=null)
                    mView.onSuccessLogin(loginBean);
            }

            @Override
            public void onFail(String error) {
                if (mView!=null)
                    mView.showToast(error);
                mView.onFail(error);
            }
        },name,pwd);

    }
    //请求验证码接口
    public void requestYanzhengma(String phone) {
        model.requestYanzhengma(new ResultCallBack<CodeBean>() {
            @Override
            public void onSuccess(CodeBean codeBean) {
                if (mView!=null)
                    mView.onSuccessCode(codeBean);
            }

            @Override
            public void onFail(String error) {
                if (mView!=null)
                    mView.showToast(error);
                mView.onFail(error);
            }
        },phone);
    }
    //手机号验证码登录接口
    public void requestLogin_byphonecode(String type,String phone,String code) {
        model.requestYanzhengma(new ResultCallBack<Loginby_phonecodeBean>() {
            @Override
            public void onSuccess(Loginby_phonecodeBean phonecodeBean) {
                if (mView!=null)
                    mView.onSuccessLogin_byphonecode(phonecodeBean);
            }

            @Override
            public void onFail(String error) {
                if (mView!=null)
                    mView.showToast(error);
                mView.onFail(error);
            }
        },type,phone,code);
    }
}
